<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of String
 *
 * @author chedim
 */
class oString extends oClass
{
    protected $value = '';
    protected $mb    = true;
    protected $enc   = 'utf-8';

    public function  __construct($value = null, $mb = true, $enc = 'utf-8')
    {
        $this->value = (string)$value;
        $this->mb    = $mb;
        $this->enc   = $enc;
    }

    public function __invoke($start, $stop = null)
    {
        if ($stop === null) {
            if ($this->mb)
                    $stop = mb_strlen($this->value, $this->enc);
            else $stop = strlen($this->value);
        }
        if ($this->mb) 
                return (string)mb_substr($this->value, $start, $stop, $this->enc);
        return (string)substr($this->value, $start, $stop);
    }

    public function encoding() {
        return $this->enc;
    }

    public function value() {
        return $this->value;
    }

    public function  __toString()
    {
        return $this->value;
    }
}
?>
